import java.util.Date;
import java.sql.*;
import java.util.Calendar;
import java.util.ArrayList;
public class Nurse extends User{

  public Nurse(String username, String password, Name name){
    super(username, password, name, 2);
  }

 public boolean createPatient(Patient newPatient){
	  return Patient.createPatient(newPatient.getUsername(), newPatient.getEncryptedPassword(), newPatient.isSuspended());
  }

 /**
   * Method that enables nurse to delete a patient
   * @return boolean of whether patient is deleted
   */
  public boolean deletePatient(String username){
	  return Patient.deletePatient(username);
  }

  //fix to return Collection<Patient>
  public Collection<Patient> getPatients(){
    String sql = "SELECT * FROM Users WHERE access_level='1'";
	  ResultSet rs = Database.selectQuery(sql);
  }
  //fix to return Collection<Appointment>
  public static Collection<Appointments> getDailyAppointments(){
    // Array list to return
    Collection<Appointments> dailyAppts = new ArrayList<Appointments>();
    //Get the time at the end of the day
    Calendar now = Calendar.getInstance();
    //Mysql date formatted as 'yyyy-mm-dd'
    //Get the year month and day
    int year = now.get(Calendar.YEAR);
    int month = now.get(Calendar.MONTH);
    int day = now.get(Calendar.DATE);
    // calculate the current date as a string
    String beforeDate = year+"-"+month+"'"+day;
    int nextDay = day + 1;
    // calculate tomorrows date as a string
    String afterDate = year+"'"+month+"'"+nextDay;
    // sql to select appointments from today
    String sql = "SELECT * FROM Appointments WHERE appt_date>'"+beforeDate+"' AND appt_date<'"+afterDate+"'";
    ResultSet rs = Database.selectQuery(sql);
    try{
      while(rs.next()){
        // construct new appointment object
        int recordId = rs.getInt("treatment_record");
        Appointment current = new Appointment(recordId);
        current.setDoctor(rs.getString("doctor");
        current.setNurse(rs.getString("nurse");
        current.setReason(rs.getString("reason");
        current.setUsername(rs.getString("username");
        // Need to parde time and date to format Gregorian calendar can recognize
        java.sql.Date date = rs.getDate("appt_date");
        java.sql.Time time = rs.getTime("appt_time");
        // convert date to string then parse
        String dateString = date.toString();
        String dateDelim = "[-]";
        String dateTokens = dateString.split(dateDelims);
        int year = Integer.parseInt(dateTokens[0]);
        int month = Integer.parseInt(dateTokens[1]);
        int day = Integer.parseInt(dateTokens[2]);
        //convert time to String then parse
        String timeString = time.toString();
        String timeDelims = "[:]";
        String[] timeTokens = timeString.split(timeDelims);
        int hour = Integer.parseInt(timeTokens[0]);
        int minutes = Integer.parseInt(timeTokens[1]);
        current.setTime(new GregorianCalendar(year, month, day, hour, minutes));
        dailyAppts.add(current);
      }
	  return dailyAppts;
  }
}
